package com.qsl.ssyx.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qsl.ssyx.product.mapper.AttrGroupMapper;
import com.qsl.ssyx.model.product.AttrGroup;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qsl.ssyx.product.service.AttrGroupService;
import com.qsl.ssyx.vo.product.AttrGroupQueryVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 属性分组 服务实现类
 * </p>
 *
 * @author 青衫泪
 * @since 2023-08-10
 */
@Service
public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupMapper, AttrGroup> implements AttrGroupService {

    //    条件分页查询
    @Override
    public IPage<AttrGroup> selectPage(Page<AttrGroup> pageParam, AttrGroupQueryVo attrGroupQueryVo) {
        LambdaQueryWrapper<AttrGroup> lqw = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(attrGroupQueryVo.getName())) {
            lqw.like(AttrGroup::getName, attrGroupQueryVo.getName());
        }
        lqw.orderByDesc(AttrGroup::getId); // 倒序排序

        Page<AttrGroup> attrGroupPage = baseMapper.selectPage(pageParam, lqw);
        return attrGroupPage;
    }

    //    查询所有平台属性分组
    @Override
    public List<AttrGroup> findAllList() {
        List<AttrGroup> attrGroupList = baseMapper.selectList(null);
        return attrGroupList;
    }
}
